//
//  AddViewController.m
//  UI09_ContactBookSample
//
//  Created by lizhongren on 15/9/27.
//  Copyright (c) 2015年 lizhongren. All rights reserved.
//

#import "AddViewController.h"
#import "UITextField+InitMethod.h"
#import "UIButton+InitButton.h"

@interface AddViewController ()

@property (nonatomic, retain) UITextField *nameField;
@property (nonatomic, retain) UITextField *ageField;
@property (nonatomic, retain) UITextField *numberField;

@end

@implementation AddViewController

- (void)dealloc
{
    [_nameField release];
    [_ageField release];
    [_numberField release];
    [super dealloc];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.view.backgroundColor = [UIColor whiteColor];
    
    self.nameField = [UITextField textFieldWithFrame:CGRectMake(20, 120, 335, 50) placeHolder:@"请输入名字"];
    [self.view addSubview:self.nameField];

    
    self.numberField = [UITextField textFieldWithFrame:CGRectMake(20, 200, 335, 50) placeHolder:@"学号"];
    [self.view addSubview:self.numberField];
    
    self.ageField = [UITextField textFieldWithFrame:CGRectMake(20, 280, 335, 50) placeHolder:@"年龄"];
    [self.view addSubview:self.ageField];
    
    UIButton *button = [UIButton buttonWithFrame:CGRectMake(20, 350, 335, 50) title:@"save" target:self action:@selector(buttonAction:) color:[UIColor yellowColor]];
    
    [self.view addSubview:button];
    
    
}

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    [self.view endEditing:YES];
}


- (void)buttonAction:(UIButton *)button
{
    // 每次在添加页面保存的时候, 都创建一个新的Student对象
    // 利用这个页面的textField中的数据给Student对象赋值
    Student *stu = [[Student alloc] init];
    
    stu.name = self.nameField.text;
    stu.number = self.numberField.text;
    stu.age = self.ageField.text;
    
    [self.delegate addStudent:stu];
    [stu release];
    
    
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
